<?php
namespace Home\Model;
use Think\Model;

/**
 * 商品分类
 */
class PresentModel extends Model {
	/**
	 * [数据获取]
	 * @Author   Axing
	 * @DateTime 2017-08-22
	 * @param    string     $where [需要判断的字段名]
	 * @return   [type]            [description]
	 */
	public function lists($where) {
		foreach($where as $k => $v) {
			if(!$v) {
				unset($where[$v]);
			} else {
				$condition[$k] = $v;
			}
		}
		
		//拼接时间区间
		if($condition['star'] && $condition['end']) {
			$sql = "created_at BETWEEN '" . $condition['star'] . "' AND '" . $condition['end'] . "'";
		}
		//end
		
		unset($condition['star']);
		unset($condition['end']);

		if(!$sql) {
			$data = $this->where($condition)->select();
		} else {
			$data = $this->where($condition)->where($sql)->select();
		}

        foreach($data as $k => &$v) {
            $data['total'] += $v['account_money'];
        }

        return $data;
	}
}